package main.java.indi.zyj.c150.dps;

import java.text.DateFormatSymbols;
import java.util.Scanner;

public class _12_PowerEq {

    static int n, M, ans;
    static int[] k = new int[5];
    static int[] p = new int[5];


    static void Dfs(int x, long s){

        if (x == n){
            if (s == 0){
                ans++;
                return;
            }
        }


        for (int i = 1; i <= M ; i++) {
            Dfs(x + 1, (long) (s + k[i] * Math.pow(i, p[x])));
        }

    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        n = scan.nextInt();
        M = scan.nextInt();

        for (int i = 0; i < n; i++) {
            k[i] = scan.nextInt();
            p[i] = scan.nextInt();
        }

        Dfs(0, 0);

        System.out.println(ans);


    }

}
